﻿using System.Windows.Input;
using NUnit.Framework;
using Primitive.Mvvm.Framework.Implementations;
using Primitive.Mvvm.Framework.Interfaces;

namespace Primitive.Mvvm.Framework.TestObjects
{
    public class TestModel
    {
        public int Id { get; set; }
        public string Desc { get; set; }

        public TestModel()
        {
            Id = 0;
            Desc = string.Empty;
        }
    }

    public class TestViewFullModel : BaseViewModel
    {
        private TestModel _model;
        public TestViewFullModel(IMediator mediator, TestModel model) : base(mediator)
        {
            _model = model;
        }

        public int Id
        {
            get { return _model.Id; }
            set
            {
                if (value == _model.Id) 
                    return;
                
                _model.Id = value;
                RaisePropertyChanged(this, () => Id);
            }
        }

        public string Desc
        {
            get { return _model.Desc; }
            set
            {
                if (value == _model.Desc)
                    return;

                _model.Desc = value;
                RaisePropertyChanged(this, () => Desc);
            }
        }

        public override void NotifyViewModelChanged(object sender, System.ComponentModel.PropertyChangedEventArgs pce)
        {
            
        }
    }

    
    public class TestViewIdModel : BaseViewModel
    {
        private TestModel _model;
        public TestViewIdModel(IMediator mediator, TestModel model)
            : base(mediator)
        {
            _model = model;
        }

        public int Id
        {
            get { return _model.Id; }
            set
            {
                if (value == _model.Id)
                    return;

                _model.Id = value;
                RaisePropertyChanged(this, () => Id);
            }
        }

        RelayCommand _changeIdCommand;
        public ICommand ChangeIdCommand
        {
            get
            {
                if (_changeIdCommand == null)
                {
                    return _changeIdCommand = new RelayCommand(Change, CanChangeId);
                }
                return _changeIdCommand;
            }
        }

        private void Change()
        {
            
        }

        private bool CanChangeId()
        {
            return true;
        }
    }

    [TestFixture]
    public class Tests
    {
        [Test]
        public void Test1()
        {
            var model = new TestModel {Id = 10, Desc = "test 10"};
            var mediator = new Mediator();

            var viewModelFull = new TestViewFullModel(mediator, model);
            var viewModelShort = new TestViewIdModel(mediator, model);

            viewModelFull.Id = 1;

            Assert.IsTrue(viewModelShort.Id == 1);
        }
    }
}
